package com.lingx.web.api.impl;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.lingx.model.IModel;
import com.lingx.model.impl.DefaultEntity;
import com.lingx.service.ModelService;
import com.lingx.web.api.IApi;
@Component
public class Api9007 extends AbstractDevApi implements IApi{
	@Resource
	private JdbcTemplate jdbcTemplate;
	@Resource
	private ModelService modelService;
	@Override
	public int getApiCode() {
		return 9007;
	}
	@Override
	public String getApiName() {
		return "获取字段属性";
	}
	@Override
	public Map<String, Object> api(Map<String, Object> param) {
		Map<String,Object> ret=IApi.getRetMap(1, "操作成功");
		String code=param.get("code").toString();
		String id=param.get("id").toString();
		DefaultEntity dm=this.modelService.getEntity(code);
		IModel m=this.modelService.getById(dm, id);
		List<Map<String,Object>> list=this.modelService.getByAnnoList(m);
		Collections.sort(list, new Comparator<Map<String,Object>>() {
			@Override
			public int compare(Map<String,Object> o1, Map<String,Object> o2) {
				Map<String,Object> m1=o1;
				Map<String,Object> m2=o2;
				return (m1.get("sort").toString().compareTo(m2.get("sort").toString())) ;
			}});
		for(int i=0;i<list.size();i++) {
			Map<String,Object> m1=list.get(i);
			m1.put("name", (i+1)+"."+m1.get("name").toString());
		}
		ret.put("data", list);
		return ret;
	}

}
